<?php

namespace Medicina\KernelBundle\Entity;

use Doctrine\ORM\EntityRepository;

class UserRepository extends EntityRepository {

    public function getUserByUsername($username) {
        $username = '\'' . $username . '\'';

        $em = $this->getEntityManager();
        $q = $em->createQueryBuilder()
                ->select('u')
                ->from('\Medicina\KernelBundle\Entity\User', 'u')
                ->where('(u.username = ' . $username . ' or u.email = ' . $username . ')')
                ->getQuery()
        ;

        try {
            return $q->getResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }
    public function getROLE_USER() {

        return $this->getEntityManager()->getRepository('\Medicina\KernelBundle\Entity\Role')->getRolUsuario();

       
    }

    public function findUserByConfirmationToken($token) {
        return $this->findOneBy(array('confirmationToken' => $token));
    }

}